<template>
  <s-layout
    title="社群"
    :tabbar="homePage"
    color="#333"
    navbar="inner1"
    :bgStyle="{
      src: theme.background_image,
      color: '#f3f5f4',
    }"
    onShareAppMessage
  >
    <view v-if="isAuditMode==true">开发中敬请期待！！！</view>
    <div
      class="page"
      v-if="isAuditMode==false"
    >
      <assNavbar title="社群">
        <template #left>
          <view class="ss-flex justify-start">
            <view
              v-if="examine"
              style="font-size: 30rpx; padding-left:20rpx;padding-right:40rpx; color: #333; font-weight: 600"
              :style="{ color: theme.title_color }"
              @click="jumpMy"
            >
              <image
                :src="sheep.$url.cdn(userInfo.avatar?userInfo.avatar:'https://liuliangbenben.oss-cn-hangzhou.aliyuncs.com/static/img/shop/default_avatar.png')"
                style="width:70rpx; height: 70rpx; margin-left: 10rpx;border-radius: 50%;"
              ></image>
            </view>
            <view v-else>
              <!-- 空占位 -->
            </view>
            <image
              src="https://jxzc-ygb.oss-cn-hangzhou.aliyuncs.com/Community/Publish.png"
              style="width: 70rpx; height: 70rpx;border-radius: 50%;"
              @click="show_submit"
            ></image>
          </view>
        </template>
      </assNavbar>
      <!-- 计算屏幕高度 控制swiper组件高度-->
      <view
        class="ss-flex-col"
        :style="`height: calc( 100vh - ${screenHeight}px)`"
      >
        <!-- 顶部v选项 -->
        <view
          v-if="examine"
          class="topTab ss-flex ss-row-between"
        >
          <view
            class="topTab-item ss-flex ss-flex-1 ss-row-center"
            v-for="(tab, index) in state.tabList"
            :key="tab"
            @click="tabActiveCli(tab,index)"
          >
            <text
              class="topTab-item-title"
              :style="{ color: state.tabActive == index ? theme.selected_color : '' }"
            >
              {{ tab }}
            </text>
          </view>
        </view>
        <!-- vip轮播卡片 -->
        <swiper
          class="tab-view ss-flex-1"
          :current="state.tabActive"
          :duration="300"
          @change="onswiperchange"
        >
          <swiper-item
            class="swiper-item"
            v-for="(tab,index) in examine ? state.tabList : state.tabList.slice(0, 1)"
            :key="tab"
          >
            <!-- 广场 -->
            <assList
              :tabsIndex="state.squareIndex"
              :listHeight="screenHeight  + 40"
              v-if="tab == '推荐'"
              :is_gc="true"
              :switchList="state.findSwitchList"
              @listSwitch="listChange($event, 'square')"
              @scrollLower="getList('square')"
              :tabsId="state.squareCategory"
            >
              <view
                class="ss-flex ss-flex-wrap ss-row-between"
                style="padding: 0 24rpx 0"
              >
                <!-- ,{...find,type:2,...find.user} -->
                <assFindCard
                  :findData="find"
                  v-for="find in state.squareList"
                  :key="find.id"
                  @like="setLike(find)"
                  @cardTap="jumpType(find, index,'square')"
                >
                </assFindCard>
              </view>
              <uni-load-more :status="state.squareLoad"></uni-load-more>
            </assList>
            <!-- 话题 -->
            <assList
              :tabsIndex="state.talkIndex"
              :listHeight="screenHeight + 40"
              v-if="tab == '话题'"
              @listSwitch="listChange($event, 'talk')"
              :switchList="state.talkSwitchList"
              @scrollLower="getList('talk')"
              :tabsId="state.talkCategory"
              :tabActive="state.tabActive"
            >
              <view style="padding-bottom: 25rpx">
                <view
                  class="talkList-item ss-flex"
                  v-for="talk in state.talkList"
                  :key="talk.id"
                  @click="sheep.$router.go('/association/pages/talk', { id: talk.id,...talk })"
                >
                  <image
                    :src="talk.image"
                    mode="aspectFill"
                  />
                  <view class="ss-flex-1 ss-flex-col pos-rel" >
                    <view class="talk-title ss-line-1">{{ talk.title }}</view>
                    <view class="talk-subtitle ss-flex-1 ss-line-2">{{ talk.sub_title }}</view>
                    <view class="talk-bottom ss-flex ss-row-between">
                      <view>{{ talk.view || 0 }}浏览</view>
                      <view>{{ talk.number || 0 }}参与</view>
                      <view>{{ sheep.$helper.timeFormat(talk.updatetime) }}更新</view>
                    </view>
                  </view>
                </view>
                <uni-load-more :status="state.talkLoad"></uni-load-more>
              </view>
            </assList>
            <!-- 发现 -->
            <assList
              :tabsIndex="state.findIndex"
              :listHeight="screenHeight + 40"
              v-if="tab == '广场'"
              :switchList="state.findSwitchList"
              @listSwitch="listChange($event, 'find')"
              @scrollLower="getList('find')"
              :tabsId="state.findCategory"
            >
              <view
                class="ss-flex ss-flex-wrap ss-row-between"
                style="padding: 0 24rpx 25rpx"
              >
                <!-- ,{...find,type:2,...find.user} -->
                <assFindCard
                  :findData="find"
                  v-for="(find, index) in state.findList"
                  :key="find.id"
                  @like="setLike(find)"
                  @cardTap="jumpType(find, index,'find')"
                >
                </assFindCard>
              </view>
              <uni-load-more :status="state.findLoad"></uni-load-more>
            </assList>
            <!-- 推荐-小程序列表 -->
            <assList
              :listHeight="screenHeight + 40"
              v-if="tab == '发现'"
            >
              <view class="appList ss-flex ss-flex-wrap">
                <view
                  class="appList-item ss-flex-col ss-col-center ss-row-center"
                  v-for="item in state.appList"
                  :key="item.image"
                  @click="toMiniProgram(item)"
                >
                  <image :src="sheep.$url.cdn(item.image)" />
                  {{ item.title }}
                </view>
              </view>
            </assList>
            <!-- 商学院 -->
            <assList
              :listHeight="screenHeight+ 40"
              v-if="state.tabActive == 4"
              :tabsIndex="state.shopIndex"
              @scrollLower="getList('shop')"
              :tabsId="state.shopCategory"
            >
              <!-- <view
                class="ss-flex ss-flex-wrap ss-row-between"
                style="padding: 0 24rpx 0"
              >
                <assFindCard
                  :findData="find"
                  v-for="find in state.shopList"
                  :key="find.id"
                  @like="setLike(find)"
                  @cardTap="jumpType(find, index,'shop')"
                >
                </assFindCard>
              </view>
              <uni-load-more :status="state.shopLoad"></uni-load-more> -->
              <view style="padding-bottom: 25rpx">
                <view
                  class="shopList-item ss-flex"
                  v-for="shop in state.shopList"
                  :key="shop.id"
                  @click="sheep.$router.go('/association/pages/talkDetail', { id: shop.id,...shop })"
                >
                  <view class="img-flex-box">
                    <image
                      :src="sheep.$url.cdn( shop.image +  (isVideo(shop.image) ? '?x-oss-process=video/snapshot,t_0,f_jpg' : ''))"
                      mode="aspectFill"
                      style="width: 176rpx;height: 176rpx;"
                    />
                  </view>
                  <view class="ss-flex-1 ss-flex-col pos-rel">
                    <view class="talk-title ss-line-1">{{ shop.title }}</view>
                    <view class="talk-subtitle ss-line-2">{{ shop.sub_title }}</view>
                    <view class="talk-bottom ss-flex justify-between" style="width:400rpx">
                      <view>{{ shop.view || 0 }}浏览</view>
                      <view>{{ shop.number || 0 }}参与</view>
                      <view>{{ sheep.$helper.timeFormat(shop.updatetime) }}更新</view>
                    </view>
                  </view>
                </view>
                <uni-load-more :status="state.shopLoad"></uni-load-more>
              </view>
            </assList>
          </swiper-item>
        </swiper>
      </view>
      <!-- 悬浮按钮 -->
      <!-- 发布按钮 -->
      <!-- 		<view v-if="examine" class="float-Btn1 ss-flex  ss-row-center" v-show="state.tabActive == 2"
			:style="{ background: theme.btn_background_color }" @click="state.releaseShow = !state.releaseShow">
			<image :src="sheep.$url.cdn(state.releaseShow ? theme.close_publish_image : theme.publish_image)"
				mode="scaleToFill" />
		</view> -->
      <!-- 兑换按钮 -->

      <su-popup
        type="center"
        @change="state.releaseShow = $event.show"
        :show="state.releaseShow"
        backgroundColor="none"
        maskBackgroundColor="rgba(0, 0, 0, 0.8)"
      >
        <view
          class="release-item ss-flex ss-row-left"
          v-for="item in state.releaseBtn"
          :key="item.title"
          @click="jump(item)"
        >
          <image
            :src="item.img_url"
            class="assIcon"
          ></image>

          <!-- <assIcon :type="item.type" size="100"></assIcon> -->
          <view
            style="padding-left: 28rpx"
            class="ss-flex-col ss-row-between"
          >
            <view>{{ item.title }}</view>
            {{ item.subTitle }}
          </view>
        </view>
      </su-popup>
      <su-popup
        type="bottom"
        @change="state.optionShow = $event.show"
        :show="state.optionShow"
        backgroundColor="#fff"
        :round="15"
        maskBackgroundColor="rgba(0, 0, 0, 0.8)"
      >
        <view class="option-box">
          <!-- <view
            class="option-box-item"
            @click="skip('image','onco')"
            style="border-bottom: 1rpx solid #f6f6f6"
            v-if="state.option.type != 'note'"
          >图片</view> -->
          <view
            class="option-box-item"
            @click="skip('video','onco')"
            style="border-bottom: 1rpx solid #f6f6f6"
            v-if="state.option.type != 'questions'"
          >视频</view>
          <view
            class="option-box-item"
            @tap="filmingClick(['video'],'onco')"
          >相机</view>
          <!-- state.option.type=='note'?['video']:state.option.type=='questions'?['image']:['image','video'] -->
          <view class="option-box-partition"></view>
          <view
            class="option-box-item"
            @click="state.optionShow = false"
          >取消</view>
        </view>
      </su-popup>
    </div>
  </s-layout>
</template>

<script setup>
import { homePage } from '@/association/config.js';
import assIcon from '@/components/ass-icon.vue';
import assList from '@/components/ass-list.vue';
import assNavbar from '@/components/ass-navbar.vue';
import assFindCard from '@/components/ass-find-card.vue';
import API from '@/association/api';
import association from '@/association/store';
import { computed, reactive, toRaw } from 'vue';
import { onLoad, onShow, onUnload, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
import sheep from '@/sheep';
const examine = computed(() => association().examine);
const isLogin = computed(() => sheep.$store('user').isLogin);
import { showAuthModal } from '@/sheep/hooks/useModal';

import appApi from '@/sheep/api/app';

const isAuditMode = computed(() => sheep.$store('app').isAuditMode);
const userInfo = computed(() => sheep.$store('user').userInfo);


const state = reactive({
  // 模块选中序号
  tabActive: 0,
  // 发布 显示
  releaseShow: false,
  // 发布按钮列表
  releaseBtn: [
    {
      id: '10',

      type: 'note',
      title: '拍日常',
      subTitle: '拍摄分享您的日常生活',

      src: '/association/pages/publishVideo',

    },
    {
      id: '12',
      type: 'visit',
      title: '探店拍',
      subTitle: '分享优秀探店视频',
      src: '/association/pages/publish',
    },
    // {
    //   id: '9',
    //   type: 'questions',
    //   title: '发问题',
    //   subTitle: '分享问题讨论解答',
    //   src: '/association/pages/publish',
    // },
  ],
  // 商学院列表
  shopList: {},
  shopLoad: 'more',
  shopCategory: '',
  shopPages: 0,
  shopIndex: 0,
  // 顶部模块
  tabList: [],
  // 发现二级菜单
  findSwitchList: [],
  // 话题二级菜单
  talkSwitchList: [],
  // 话题列表
  talkList: {},
  talkLoad: 'more',
  talkPages: 0,
  talkIndex: 0,
  talkCategory: '',

  // 发现列表
  findList: {},
  findLoad: 'more',
  findPages: 0,
  findIndex: 0,
  findCategory: '',

  // 广场列表
  squareList: {},
  squareLoad: 'more',
  squarePages: 0,
  squareIndex: 0,
  squareCategory: '',

  // 小程序列表
  appList: [],

  // 选择探店
  optionShow: false,
  option: {},
  // 保存taBarId
  taBarId: 0
});

async function show_submit () {
  // 打印登录状态值
  if (sheep.$store('user').isLogin) {
    state.optionShow = true;
    // state.releaseShow = !state.releaseShow;
  } else {

    try {
      await showAuthModal();
      // state.releaseShow = !state.releaseShow;
    } catch (error) {
      uni.showToast({
        title: '请先登录',
        icon: 'none',
      });
    }
  }
}

const jumpMy = () => {
  sheep.$router.go('/pages/user/userCenter/index', {
    id: association().userInfo.user_id,
  });
};

const jumpType = (item, index, type) => {
  association().goType = type
  // let platform = import.meta.env.SHOPRO_UDID_NAME;
  // console.log(toRaw(item));

  // // sheep.$router.go('/association/pages/find', { id: item.find_id, type: item.label });

  // if (item.label === 'visit_' + platform || item.label === 'share_' + platform) {
  //   if (item.file_type === 'video') {
  //     // // 跳转视频
  //     sheep.$router.go('/association/pages/asvideos', {
  //       id: item.find_id,
  //       index: index,
  //       category_id: state.findCategory,
  //     });
  //   } else {
  //     sheep.$router.go('/association/pages/find', { id: item.find_id, type: item.label });
  //   }
  // }

  // if (item.label === 'questions_' + platform) {
  //   sheep.$router.go('/association/pages/find', { id: item.find_id, type: item.label });
  // }

  if (item.file_type === 'video') {
    // TODO 这里暂时做一个死判断，因为广场就不需要传category了 不然会查询出问题
    // // 跳转视频
    sheep.$router.go('/association/pages/asvideos', {
      id: item.find_id,
      index: index,
      type: item.list_type || '',
      category_id: state.tabActive !== 0 ? '' : state.findCategory,
    });
  } else {
    sheep.$router.go('/association/pages/find', {
      id: item.find_id,
      type: item.label,
      ...item,
    });
  }
};
const filmingClick = (type, status) => {
  state.optionShow = false;
  uni.chooseMedia({
    count: 1,
    mediaType: type, // 可以是['image']、['video']或['image','video']
    sourceType: ['camera'], // 只调用相机
    camera: 'back', // 使用后置摄像头
    maxDuration: 30, // 拍摄视频最长拍摄时间，单位秒
    success: (res) => {
      const { type } = res
      if (type === 'video') {
        sheep.$router.go('/association/pages/publishVideo', {
          id: state.option.id,
          path: res.tempFiles[0].tempFilePath,
          width: res.tempFiles[0].width,
          height: res.tempFiles[0].height,
          duration: res.tempFiles[0].duration,
          size: res.tempFiles[0].size,
          thumbTempFilePath: res.tempFiles[0].thumbTempFilePath,
        });
      } else {
        sheep.$router.go(state.option.src, {
          id: state.option.id,
          image: res.tempFiles[0].tempFilePath,
          size: res.tempFiles[0].size,
        });
      }

    },
    fail: (err) => {
    }
  });
}
const skip = (type, status) => {
  state.optionShow = false;
  // #ifdef MP-WEIXIN
  uni.chooseMedia({
    mediaType: [type],
    sourceType: ['album'],
    maxDuration: 30,
    success (res) {
      if (type === 'video') {
        sheep.$router.go('/association/pages/publishVideo', {
          id: state.option.id,
          path: res.tempFiles[0].tempFilePath,
          width: res.tempFiles[0].width,
          height: res.tempFiles[0].height,
          duration: res.tempFiles[0].duration,
          size: res.tempFiles[0].size,
          thumbTempFilePath: res.tempFiles[0].thumbTempFilePath,
        });
      } else {
        sheep.$router.go(state.option.src, {
          id: state.option.id,
          image: res.tempFiles[0].tempFilePath,
          size: res.tempFiles[0].size,
        });
      }
    },
  });
  // #endif
};

const jump = (item) => {
  state.releaseShow = false;
  // 打开弹窗
  state.optionShow = true;
  // 赋值数据
  state.option = item;
  state.taBarId = item.id;
  // if (item.type === 'note') {
  //   // state.optionShowCopy = true
  //   // 选择完视频跳转到发布页面
  //   // 微信小程序使用 chooseMedia 可以获取视频第一帧作为封面图
  //   // #ifdef MP-WEIXIN
  //   // uni.chooseMedia({
  //   //   mediaType: ['video'],
  //   //   count: 1, // 限制只能选择1个视频
  //   //   sourceType: ['album'],
  //   //   maxDuration: 30,
  //   //   success (res) {
  //   //     sheep.$router.go(item.src, {
  //   //       id: item.id,
  //   //       path: res.tempFiles[0].tempFilePath,
  //   //       width: res.tempFiles[0].width,
  //   //       height: res.tempFiles[0].height,
  //   //       duration: res.tempFiles[0].duration,
  //   //       size: res.tempFiles[0].size,
  //   //       thumbTempFilePath: res.tempFiles[0].thumbTempFilePath,
  //   //     });
  //   //   },
  //   // });
  //   // // #endif
  //   // // #ifdef APP
  //   // uni.chooseVideo({
  //   //   sourceType: ['album'],
  //   //   compressed: false,
  //   //   success (res) {
  //   //     sheep.$router.go(item.src, {
  //   //       path: res.tempFilePath,
  //   //       width: res.width,
  //   //       height: res.height,
  //   //       duration: res.duration,
  //   //       size: res.size,
  //   //       thumbTempFilePath: res.thumbTempFilePath,
  //   //     });
  //   //   },
  //   // });
  //   // #endif
  // } else if (item.type === 'visit') {
  //   state.option = item;
  //   state.optionShow = true;
  // } else {
  //   // 其他操作
  //   sheep.$router.go(item.src, {
  //     id: item.id,
  //   });
  // }
};

// 切换发现喜欢状态
async function setLike (item) {
  let res = await API.findLike({
    find_id: item.find_id,
  });
  item.is_likes = !!res.data.is_like;
  if (item.is_likes) {
    item.likes += 1;
  } else {
    item.likes -= 1;
  }
}

function showMsg (msg, time = '1500', type = 'none') {
  uni.showToast({
    title: '微信唤起失败，请检查是否有微信应用',
    icon: type,
    duration: time,
  });
}

function openMiniProgram (miniId) {
  if (miniId) return showMsg('暂未开放');
  plus.share.getServices(
    (service) => {
      let sweixin = service.find((s) => s.id == 'weixin');
      //判断是否有微信
      if (sweixin) {
        //唤起微信跳转小程序
        sweixin.launchMiniProgram(
          {
            id: miniId,
          },
          (res) => console.log('微信小程序唤起成功'),
          (err) => {
            console.log('微信唤起失败', err);
            showMsg('微信唤起失败，请检查是否有微信应用');
          },
        );
      } else {
        showMsg('微信唤起失败，请检查是否有微信应用');
      }
    },
    function (e) {
      console.log('微信唤起失败', e);
      showMsg('微信唤起失败，请重试');
    },
  );
}
const toMiniProgram = (app) => {
  if (!app.link || app.link == '#')
    return uni.showToast({
      icon: 'none',
      title: '暂未开放',
      duration: 1000,
    });
  // #ifdef MP-WEIXIN
  uni.navigateToMiniProgram({
    appId: app.appid,
    path: app.link,
    // 发现中启动小程序版本  develop（开发版），trial（体验版），release（正式版）
    envVersion: app.envVersion,
    extraData: {
      // 'data1': 'test'
    },
    success (res) {
      // 打开成功
      console.log(res);
    },
  });
  // #endif
  // #ifdef APP
  openMiniProgram(app.original_id);
  // #endif
  // #ifdef H5
  if (sheep.$platform.inApp) {
    openMiniProgram(app.original_id);
  } else {
    uni.showToast({
      icon: 'none',
      title: '暂未开放',
      duration: 1000,
    });
  }
  // #endif
};

const theme = computed(() => association().theme);

// 隐藏原生tabBar
uni.hideTabBar();
// 小程序模板数据
const template = computed(() => sheep.$store('app').template.user);
const screenHeight = computed(
  () =>
    84 + 20 + sheep.$platform.device.statusBarHeight + sheep.$platform.device.safeAreaInsets.bottom,
);
// swiper组件 页面模块翻页同步页数
const onswiperchange = (e) => {
  state.tabActive = e.target.current || e.detail.current;
  console.log(state.tabActive);

};
// ass-list组件触底事件
function scrollLower () {
  console.log('触底');
}

const login = async () => {
  let res = await API.login();
};
// 获取首页小程序数据
const getIndexInfo = async (platform) => {
  // #ifdef H5
  var res = await API.index(platform, {
    device: 'h5',
  });
  // #endif
  // #ifdef MP-WEIXIN
  var res = await API.index(platform, {
    device: 'miniapp',
  });
  // #endif

  if (res.data.platform.examine_status == 1) {
    // state.tabList = ['广场', '话题', '发现', '推荐'];
    state.tabList = ['推荐', '话题', '广场', '发现', '商学院'];
  } else {
    state.tabList = ['推荐', '话题', '发现', '广场', '商学院'];
  }

  if (res.code) {
    state.appList = res.data.lists;
  }
};

const getList = async (type) => {
  if (!type) return;
  if (state[`${type}Load`] == 'no-more') return;
  state[`${type}Load`] = 'loading';
  let data = {
    page: state[`${type}Pages`] + 1,
  };
  if (type !== 'find') {
    if (state[`${type}Category`] !== '') data['category_id'] = state[`${type}Category`];
    if (type == 'shop') {
      data['type'] = 'school';
    }
  }
  const res = await API[`get${type}List`](data);
  state[`${type}Pages`] = res.data.current_page;
  let list = res.data.data;

  //这个是二级菜单id  findCategory
  if (state[`${type}Pages`] <= 1) {
    state[`${type}List`] = list;
  } else {
    state[`${type}List`].push(...list);
  }
  association()[`${type}List`] = state[`${type}List`]
  state[`${type}Load`] =
    list.length >= 10 && res.data.total != state[`${type}List`].length ? 'more' : 'no-more';
};
const tabActiveCli = (val, inx) => {
  state.tabActive = inx
}
const isVideo = (link) => {
  const mp4 = /.*\.mp4$/;
  const MP4 = /.*\.MP4$/;
  console.log('????',mp4.test(link) || MP4.test(link))
  return mp4.test(link) || MP4.test(link);
};

const listChange = (e, type) => {
  state[`${type}Index`] = e.index;
  state[`${type}Load`] = 'more';
  state[`${type}Pages`] = 0;
  state[`${type}Category`] = e.id;
  getList(type);
};

// 获取发现列表
const getfindList = async () => {
  if (state.findLoad == 'no-more') return;
  state.findLoad = 'loading';
  let data = {
    page: state.findPages + 1,
  };
  if (state.findCategory !== '') data['category_id'] = state.findCategory;
  const res = await API.getfindList(data);
  state.findPages = res.data.current_page;
  let list = res.data.data;
  if (state.findPages <= 1) {
    state.findList = list;
  } else {
    state.findList.push(...list);
  }

  state.findLoad = list.length >= 10 ? 'more' : 'no-more';
};

const findChange = (e) => {
  state.findIndex = e.index;
  state.findLoad = 'more';
  state.findPages = 0;
  state.findCategory = e.id;
  getfindList();
};

// 获取广场列表
const getsquareList = async () => {
  console.log('监听获取广场列表');

  if (state.squareLoad == 'no-more') return;
  state.squareLoad = 'loading';
  let data = {
    page: state.squarePages + 1,
  };
  if (state.squareCategory !== '') {
    data['category_id'] = state.squareCategory;
  }
  const res = await API.getsquareList(data);
  state.squarePages = res.data.current_page;
  let list = res.data.data;
  if (state.squarePages <= 1) {
    state.squareList = list;
  } else {
    state.squareList.push(...list);
  }
  console.log('查看列表数据===========', state.squareList);

  state.squareLoad = list.length >= 10 ? 'more' : 'no-more';
};

const squareChange = (e) => {
  state.squareIndex = e.index;
  state.squareLoad = 'more';
  state.squarePages = 0;
  state.squareCategory = e.id;
  getsquareList();
};
// 获取话题/发现 二级分类
const getCategory = async (type) => {
  let res = await API.getCategory({
    // 话题传 topic， 发现传 find
    type,
  });

  if (res.code) {
    if (type == 'topic') {
      // console.log('这是社群');

      state.talkSwitchList = res.data.lists;

      state.talkCategory = res.data.lists[0].id;
      console.log('话题二级菜单id', state.talkCategory);

      getList('talk');

    } else if (type == 'find') {
      // state.findSwitchList = res.data.lists;
      // 这个是二级菜单id
      state.findCategory = res.data.lists[0].id;
      // state.squareCategory = res.data.lists[0].id;
      state.shopCategory = [...res.data.lists].reverse()[0].id;
      getList('find');
      getList('square');
      // 获取商学院列表
      getList('shop');


      state.releaseBtn.forEach((item, index) => {
        item.id = res.data.lists[index].id;
        item.title = res.data.lists[index].name;
        item.subTitle = res.data.lists[index].description;
        item.img_url =
          'http://liuliangbenben.oss-cn-hangzhou.aliyuncs.com' + res.data.lists[index].image;
      });
      console.log(state.releaseBtn);

    }
  }
};
const setCollection = (obj) => {
  function set (list, data) {
    state[list].find((item) => {
      if (data.id == item.find_id) {
        if (item.is_likes != data.is_likes) {
          data.is_likes ? (item.likes += 1) : (item.likes -= 1);
          item.is_likes = data.is_likes;
        }
        return true;
      } else {
        return false;
      }
    });
  }
  set('findList', obj);
  set('squareList', obj);
};
onShow(() => {
  if (association().optionShow) {
    listReset('square');
    // listReset('square');
    getList('square');
    // getList('square');
  }
  if (association().goType) {
    console.log(association()[`${association().goType}List`]);

    state[`${association().goType}List`] = association()[`${association().goType}List`]
  }

});
onUnload(() => {
  uni.$off('setCollection');
  uni.$off('refreshData');
  association().goType = null
});

onLoad(async () => {

  uni.$on('setCollection', (res) => {
    setCollection(res);
  });
  uni.$on('tabFun', () => {
    state.tabActive = 0;
    state.findCategory = state.taBarId;
  })
  // 获取小程序列表
  getIndexInfo();
  // 话题列表
  // 获取话题二级菜单
  getCategory('topic');
  // 获取发现二级菜单
  getCategory('find');
});

const listReset = (type) => {
  state[`${type}Load`] = 'more';
  state[`${type}Index`] = 0;
  state[`${type}Pages`] = 0;
};
// 页面下拉刷新
onPullDownRefresh(() => {
  listReset('talk');
  listReset('find');
  listReset('square');
  listReset('shop');
  // 获取小程序列表
  getIndexInfo();
  // 话题列表
  // getTalkList()
  // 获取话题二级菜单
  getCategory('topic');
  // 获取发现二级菜单
  getCategory('find');
  setTimeout(function () {
    uni.stopPullDownRefresh();
  }, 500);
});
// onPageScroll(() => { });
</script>

<style lang="scss" scoped>
view {
  box-sizing: border-box;
}

.assIcon {
  display: block;
  width: 100rpx;
  height: 100rpx;
}

.navbar {
  .navbar-placeholder {
    height: 44px;
  }

  .navbar-center {
    width: 100vw;
    position: fixed;
    background-size: 100% 100% !important;

    .center {
      height: 44px;
      position: relative;
    }

    .navbar-title {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      font-size: 36rpx;
      font-weight: 700;
      color: #fff;
    }

    .navbar-rightBtn {
      color: #fff;
      font-size: 32rpx;
      height: 100%;
      width: 100%;
      position: absolute;
      top: 0;
      left: 0;
      padding-left: 20rpx;
    }
  }
}

.shopInfo {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 5;
  width: 100%;
  height: 75rpx;
  border-radius: 20rpx;
  background: rgba(131, 143, 157, 0.45);
  padding: 10rpx;

  & > image {
    width: 60rpx;
    height: 60rpx;
    margin-right: 15rpx;
  }

  font-size: 32rpx;
  color: #fff;
}

.release-item {
  width: 420rpx;
  height: 100rpx;
  margin: 80rpx 0;

  & > view {
    height: 100rpx;
    color: #a1a1a1;
    font-size: 28rpx;

    & > view {
      color: #fff;
      font-size: 40rpx;
    }
  }
}

.shopList-item {
  margin: 25rpx 25rpx 0;
  padding: 25rpx;
  background-color: #fff;
  border-radius: 10rpx;

  .img-flex-box {
    width: 176rpx;
    height: 176rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* 防止图片超出容器 */
    margin-right: 20rpx;
  }
  & > view {
    height: 176rpx;
    max-height: 176rpx;
    color: #3d3d3d;
  }

  .talk-title {
    font-size: 32rpx;
  }

  .talk-subtitle {
    font-size: 24rpx;
    margin-top: 10rpx;
  }

  .talk-bottom {
    color: #b0b0b0;
    font-size: 24rpx;
	position: absolute;
	bottom: 0;
  }
}
.talkList-item {
  margin: 25rpx 25rpx 0;
  padding: 25rpx;
  background-color: #fff;
  border-radius: 10rpx;

  & > image {
    height: 176rpx;
    width: 176rpx;
    min-width: 176rpx;
    margin-right: 25rpx;
  }

  & > view {
    height: 176rpx;
    max-height: 176rpx;
    color: #3d3d3d;
  }

  .talk-title {
    font-size: 32rpx;
  }

  .talk-subtitle {
    font-size: 24rpx;
    margin-top: 10rpx;
  }

  .talk-bottom {
    color: #b0b0b0;
    font-size: 24rpx;
  }
}

.topTab {
  width: 100vw;
  background-color: #fff;

  .topTab-item {
    height: 40px;
    font-size: 16px;

    .topTab-item-title {
      color: #3d3d3d;
      font-size: 32rpx;

      &-active {
        color: #0ad5ea;
      }
    }
  }
}

.float-Btn1 {
  bottom: calc(300rpx + env(safe-area-inset-bottom)) !important;
  z-index: 100000;
}

.float-Btn1,
.float-Btn2 {
  position: fixed;
  right: 25rpx;
  bottom: calc(150rpx + env(safe-area-inset-bottom));
  width: 120rpx;
  height: 120rpx;
  background-color: #b5f8ff;
  border-radius: 50%;

  & > image {
    width: 72rpx;
    height: 72rpx;
  }
}

.appList {
  padding: 20rpx;

  .appList-item {
    width: 25%;
    margin: 20rpx 0;

    & > image {
      margin-bottom: 16rpx;
      border-radius: 20rpx;
      width: 120rpx;
      height: 120rpx;
      box-shadow: 0px 4px 10px 0px rgba(167, 167, 167, 0.302);
    }
  }
}

.option-box {
  width: 100%;

  .option-box-item {
    width: 100%;
    height: 100rpx;
    font-size: 32rpx;
    font-weight: normal;
    line-height: 100rpx;
    text-align: center;
  }

  .option-box-partition {
    width: 100%;
    height: 30rpx;
    background-color: #f6f6f6;
  }
}
.pos-rel{
	position: relative;
}
</style>
